package com.powernode.proxy.service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;



//专门负责计时的一个调用处理器
public class TimeInvocationHandler implements InvocationHandler {
    private Object target;

    public TimeInvocationHandler(Object target) {
        this.target = target;
    }


    /*
    proxy:代理对象
    method：目标对象的目标方法
    args：目标方法上的实参
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        long begin =System.currentTimeMillis();
        Object retValue =method.invoke(target,args);
       long end =System.currentTimeMillis();
        System.out.println("耗时"+(end-begin)+"毫秒");
        return retValue;
    }
}
